home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
yase.arc
/
EDIT4.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-12-13
|
5KB
|
151 lines
******************************************************************
* COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
* - Note: This is a real, live, actual, registered copyright,
* and should be treated as such. This source code is from
* the book "68000 Assembly Language", Krantz and Stanley,
* Addison-Wesley Publishing Company, Reading, MA, 1986.
*
* Permission granted by the authors for non-commercial use
* in programs released to the public domain, as long as this
* copyright notice remains attached and visible.
*
*****************************************************************
* Editor Auxiliary Functions
xref cmd_w,lineed,printf,to_end,write_out
xdef prompt,dirty,ask,eof,cnt_nl,seek,chk_blk,default
xdef putfile
#edit.h
*****************************************************************
* EOF - moves cursor to end of file
eof:
bsr to_end * move everything before cursor
bsr cnt_nl * count newlines behind cursor
rts
*****************************************************************
* CNT_NL - count newlines behind cursor
cnt_nl:
move.l b_buf(a5),a0 * a0 is search start address
move.l b_gap(a5),d0 * compute number of bytes
sub.l a0,d0 * d0 is number of file bytes
clr.w d1 * d1 is newline counter
move.b #10,d2 * do register compare - faster
bra sk0_nl * loop test before loop body
lp0_nl:
cmp.b (a0)+,d2 * look for newline
bne sk0_nl * nope.
addq.w #1,d1 * increment line counter
sk0_nl:
dbra d0,lp0_nl * loop test
move.w d1,log_lin(a5) * save new logical line count
rts
*****************************************************************
* DIRTY - marks file as modified, and clears block markers
dirty:
clr.l blk_st(a5) * reset block start marker
clr.l blk_end(a5) * reset block end marker
move.w #-1,modify(a5) * set file modified flag
rts
*****************************************************************
* SEEK - moves the cursor to the location in d0
seek:
move.l b_gap(a5),a0 * gap start address in A0
move.l e_gap(a5),a1 * gap end location in A1
sub.l a0,d0 * calculate characters to dest.
bgt sk1_sk * move towards end of file
neg.w d0 * take abs() of char count
bra sk2_sk * loop test before branch
lp0_sk:
move.b -(a0),-(a1) * move towards start of file
sk2_sk:
dbra d0,lp0_sk * to start of file loop
bra sk0_sk * get out
lp1_sk:
move.b (a1)+,(a0)+ * move towards end of file
sk1_sk:
dbra d0,lp1_sk * to end of file loop
sk0_sk:
move.l a0,b_gap(a5) * reset gap start address
move.l a1,e_gap(a5) * reset gap end address
rts
*****************************************************************
* CHK_BLK - checks for valid block markers
chk_blk:
tst.l blk_st(a5) * check if start is marked
beq sk0_cb * branch if not
tst.l blk_end(a5) * check if end is marked
beq sk1_cb * branch if not
move.l blk_end(a5),d0 * check if end is after start
cmp.l blk_st(a5),d0
ble sk3_cb * branch if mismarked
clr.w d0 * get "ok" return code
bra sk2_cb * branch out
sk0_cb:
move.w #7,ed_err(a5) * show start not marked error
bra sk2_cb
sk1_cb:
move.w #8,ed_err(a5) * show end not marked error
bra sk2_cb
sk3_cb:
move.w #9,ed_err(a5) * show mismark error
sk2_cb:
rts
*****************************************************************
* DEFAULT: User hits unspecified subcommand key
default:
rts
*****************************************************************
* PUTFILE - puts the file to disk - returns D0 nonzero on error
putfile:
bsr to_end * move all text behind cursor
lea fname(a5),a0 * load name for file write
move.l b_buf(a5),a1 * start of data to write
move.l b_gap(a5),d1 * calculate number of bytes
sub.l a1,d1 * D1 is numbers of bytes to write
bsr write_out * write the file to disk
tst.w d0 * check return code
beq sk0_pf * skip error message with no err
move.w #3,ed_err(a5) * load edit error code
sk0_pf:
rts
*****************************************************************
* PROMPT - outputs a prompt in command window. A0 points to prmt
prompt:
move.l a0,-(a7) * push parameter string address
move.l #cmd_w,a0 * get command window address
move.w w_ulcy(a0),-(a7) push Y screen address
move.w w_ulcx(a0),-(a7) push X screen address
move.l #p_str,-(a7) * push format string address
bsr printf * output prompt
addq.l #8,a7 * adjust stack
move.l (a7)+,a0 * restore a0
rts
p_str: dc.b '%v%-78s',0
dc.w 0
*****************************************************************
* ASK - prompts human for string input - A0 is prompt string,
* A1 is input string
ask:
bsr prompt * output prompt string
move.l #cmd_w,a2 * a2 has output limits
move.w w_ulcx(a2),d0 * d0 will count be X offset
lp0_ask:
tst.b (a0)+ * see if we have a null
beq sk0_ask * jump out if null
addq.w #1,d0 * increment X position
bra lp0_ask * loop again for strlen
sk0_ask:
move.w w_lrcx(a2),d1 * d1 is input window right edge
sub.w d0,d1 * d1 is now max chars in input
move.w d1,-(a7) * push max number for lineed
move.w d0,-(a7) * push screen column
move.w w_ulcy(a2),-(a7) push screen line
move.l a1,-(a7) * push input string address
bsr lineed * go edit input line
add.l #10,a7 * adjust stack
rts
end